SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WebDepartments]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WebDepartments](
	[DepartmentID] [int] IDENTITY(1,1) NOT NULL,
	[DepartmentName] [varchar](50) NOT NULL,
	[About] [varchar](500) NOT NULL,
	[ParentID] [int] NULL,
	[SortNumber] [int] NOT NULL,
	[UpdateDate] [datetime] NOT NULL,
	[Operator] [varchar](50) NULL,
	[Status] [int] NOT NULL,
	[DeptLevel] [int] NULL,
 CONSTRAINT [PK_WebDepartments] PRIMARY KEY CLUSTERED 
(
	[DepartmentID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WebManageMenus]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WebManageMenus](
	[MenuID] [int] IDENTITY(1,1) NOT NULL,
	[MenuName] [varchar](50) NOT NULL,
	[ParentID] [int] NULL,
	[MenuLevel] [int] NOT NULL,
	[LinkUrl] [varchar](300) NULL,
	[About] [varchar](200) NOT NULL,
	[SortNumber] [int] NOT NULL,
	[UpdateDate] [datetime] NOT NULL,
	[Operator] [varchar](50) NULL,
	[Status] [int] NOT NULL,
 CONSTRAINT [PK_WebManageMenus] PRIMARY KEY CLUSTERED 
(
	[MenuID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WebManagePermissions]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WebManagePermissions](
	[PermissionsID] [int] NOT NULL,
	[Name] [varchar](100) NOT NULL,
	[Status] [int] NOT NULL,
	[CreateDate] [datetime] NOT NULL,
	[UpdateDate] [datetime] NOT NULL,
 CONSTRAINT [PK_WebManagePermissions] PRIMARY KEY CLUSTERED 
(
	[PermissionsID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WebSystem]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WebSystem](
	[WebSystemID] [int] NOT NULL,
	[WebSystemName] [nvarchar](128) NOT NULL,
	[Info] [nvarchar](max) NULL,
	[Status] [int] NOT NULL,
 CONSTRAINT [PK_WebSystem] PRIMARY KEY CLUSTERED 
(
	[WebSystemID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WebManageRoles]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WebManageRoles](
	[ManageRoleID] [int] IDENTITY(1,1) NOT NULL,
	[RoleName] [varchar](50) NOT NULL,
	[DepartmentID] [int] NOT NULL,
	[About] [varchar](200) NOT NULL,
	[UpdateDate] [datetime] NOT NULL,
	[SortNumber] [int] NOT NULL,
	[Operator] [varchar](50) NOT NULL,
	[Status] [int] NOT NULL,
	[OperatorAuthority] [int] NOT NULL,
 CONSTRAINT [PK_WebManageRoles] PRIMARY KEY CLUSTERED 
(
	[ManageRoleID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WebManageUsers]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WebManageUsers](
	[ManageUserID] [int] IDENTITY(1,1) NOT NULL,
	[LoginName] [varchar](20) NOT NULL,
	[Password] [varchar](50) NOT NULL,
	[RealName] [varchar](20) NOT NULL,
	[Mobile] [varchar](20) NULL,
	[Email] [varchar](50) NULL,
	[Description] [nvarchar](max) NULL,
	[DepartmentID] [int] NOT NULL,
	[CreateDate] [datetime] NOT NULL,
	[UpdateDate] [datetime] NOT NULL,
	[Operator] [varchar](50) NULL,
	[Status] [int] NOT NULL,
	[WebSystemID] [int] NULL,
 CONSTRAINT [PK_WebManageUsers] PRIMARY KEY CLUSTERED 
(
	[ManageUserID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WebManageRole_WebManageMenus]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WebManageRole_WebManageMenus](
	[WebManageMenus_MenuID] [int] NOT NULL,
	[WebManageRoles_ManageRoleID] [int] NOT NULL,
 CONSTRAINT [PK_WebManageRole_WebManageMenus] PRIMARY KEY NONCLUSTERED 
(
	[WebManageMenus_MenuID] ASC,
	[WebManageRoles_ManageRoleID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WebManageUser_WebManageRoles]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WebManageUser_WebManageRoles](
	[WebManageRoles_ManageRoleID] [int] NOT NULL,
	[WebManageUsers_ManageUserID] [int] NOT NULL,
 CONSTRAINT [PK_WebManageUser_WebManageRoles] PRIMARY KEY NONCLUSTERED 
(
	[WebManageRoles_ManageRoleID] ASC,
	[WebManageUsers_ManageUserID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WebDepartments_WebDepartments]') AND parent_object_id = OBJECT_ID(N'[dbo].[WebDepartments]'))
ALTER TABLE [dbo].[WebDepartments]  WITH CHECK ADD  CONSTRAINT [FK_WebDepartments_WebDepartments] FOREIGN KEY([ParentID])
REFERENCES [dbo].[WebDepartments] ([DepartmentID])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WebManageMenus_WebManageMenus]') AND parent_object_id = OBJECT_ID(N'[dbo].[WebManageMenus]'))
ALTER TABLE [dbo].[WebManageMenus]  WITH CHECK ADD  CONSTRAINT [FK_WebManageMenus_WebManageMenus] FOREIGN KEY([ParentID])
REFERENCES [dbo].[WebManageMenus] ([MenuID])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WebManageRoles_WebDepartments1]') AND parent_object_id = OBJECT_ID(N'[dbo].[WebManageRoles]'))
ALTER TABLE [dbo].[WebManageRoles]  WITH CHECK ADD  CONSTRAINT [FK_WebManageRoles_WebDepartments1] FOREIGN KEY([DepartmentID])
REFERENCES [dbo].[WebDepartments] ([DepartmentID])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WebManageUsers_WebDepartments1]') AND parent_object_id = OBJECT_ID(N'[dbo].[WebManageUsers]'))
ALTER TABLE [dbo].[WebManageUsers]  WITH CHECK ADD  CONSTRAINT [FK_WebManageUsers_WebDepartments1] FOREIGN KEY([DepartmentID])
REFERENCES [dbo].[WebDepartments] ([DepartmentID])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WebManageRole_WebManageMenus_WebManageMenus]') AND parent_object_id = OBJECT_ID(N'[dbo].[WebManageRole_WebManageMenus]'))
ALTER TABLE [dbo].[WebManageRole_WebManageMenus]  WITH CHECK ADD  CONSTRAINT [FK_WebManageRole_WebManageMenus_WebManageMenus] FOREIGN KEY([WebManageMenus_MenuID])
REFERENCES [dbo].[WebManageMenus] ([MenuID])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WebManageRole_WebManageMenus_WebManageRoles]') AND parent_object_id = OBJECT_ID(N'[dbo].[WebManageRole_WebManageMenus]'))
ALTER TABLE [dbo].[WebManageRole_WebManageMenus]  WITH CHECK ADD  CONSTRAINT [FK_WebManageRole_WebManageMenus_WebManageRoles] FOREIGN KEY([WebManageRoles_ManageRoleID])
REFERENCES [dbo].[WebManageRoles] ([ManageRoleID])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WebManageUser_WebManageRoles_WebManageRoles]') AND parent_object_id = OBJECT_ID(N'[dbo].[WebManageUser_WebManageRoles]'))
ALTER TABLE [dbo].[WebManageUser_WebManageRoles]  WITH CHECK ADD  CONSTRAINT [FK_WebManageUser_WebManageRoles_WebManageRoles] FOREIGN KEY([WebManageRoles_ManageRoleID])
REFERENCES [dbo].[WebManageRoles] ([ManageRoleID])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_WebManageUser_WebManageRoles_WebManageUsers]') AND parent_object_id = OBJECT_ID(N'[dbo].[WebManageUser_WebManageRoles]'))
ALTER TABLE [dbo].[WebManageUser_WebManageRoles]  WITH CHECK ADD  CONSTRAINT [FK_WebManageUser_WebManageRoles_WebManageUsers] FOREIGN KEY([WebManageUsers_ManageUserID])
REFERENCES [dbo].[WebManageUsers] ([ManageUserID])
